package com.cyz.common.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyz.common.bean.Menu;
import com.cyz.common.mapper.MenuMapper;
import com.cyz.common.service.MenuService;
import com.cyz.common.service.RoleMenuService;
import com.cyz.common.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author 34928
* @description 针对表【menu(菜单权限表)】的数据库操作Service实现
* @createDate 2023-02-22 11:39:30
*/
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu>
    implements MenuService {

    @Autowired
    private UserRoleService userRoleService;
    @Autowired
    private RoleMenuService roleMenuService;

    @Override
    public List<String> queryMenusByUserId(Integer id) {
        //根据userID 查询角色id
        List<Integer> roleIds = userRoleService.getRoleIdsByUserId(id);
        //根据角色id 查询菜单id
        List<Integer> menuIds = roleMenuService.getMenuIdsByRoleIds(roleIds);
        //根据菜单id 查询权限
        Set<String> set = new HashSet<>();
        menuIds
                .forEach(item -> {
                    set.add(getById(item).getPerms());
                });
        return new ArrayList<>(set);
    }
}




